import type { NextConfig } from "next";
import path from 'node:path';
import url from 'node:url';
import fs from 'node:fs';
console.log(process.env.JWT_SECRET)
const cert = readTls("fullchain.pem");
const key = readTls("privkey.pem");
// console.log("------<",key,cert)
const nextConfig: NextConfig = {
   basePath: process.env.BASE_PATH,

  //  turbopack: {
  //   rules: {
  //     '**/*.glsl': {
  //       loaders: ['raw-loader'], // Turbopack 支持 raw-loader
  //       as: '*.js', // 告诉 Turbopack 把 .glsl 当作 JS 模块处理
  //     },
  //     '**/*.vert': {
  //       loaders: ['raw-loader'],
  //       as: '*.js',
  //     },
  //     '**/*.frag': {
  //       loaders: ['raw-loader'],
  //       as: '*.js',
  //     },
  //   },
  // },

  async rewrites() {
  // console.log(999)
    return [
      {
        
        
        source: '/perf/:path*',
        destination: 'https://lizhan.fun/perf/:path*', // 代理到后端接口
      },
    ];
  },
  
  /* config options here */
};
function readTls(v: string) {
  if (!v) {
    return;
  }

  if (!path.isAbsolute(v)) {
    const dir = path.dirname(url.fileURLToPath(import.meta.url));

    v = path.join(dir, './src/keys', v);
  }

  try {
    return fs.readFileSync(v);
  } catch (error) {
    console.log(error)

    // Ignore file not found.
  }
}
export default nextConfig;
